//角色管理模块
import request from "@/utlis/request";
import type {
  IRoleResponseData,
  IPage,
  IRole,
  ISave,
  IRoleListResponseData,
  IDeleteResponseData,
} from "@/api/acl/type";

enum API {
  ROLEFINDALL_URL = "/role/findAll", //查询所有的
  ALLROLE_URL = "/role/findPage", //列表查询
  DELETEROLE_URL = "/role/delete", //删除
  SAVEROLE_URL = "/role/save", //新增或编辑
  ROLEMENUS_URL = "/role/findRoleMenus", //查询角色菜单
  SAVEROLEMENUS_URL = "/role/saveRoleMenus", //保存角色菜单权限
}

export const reqRoleFindAll = async () => {
  return request.get<any, IRoleResponseData>(API.ROLEFINDALL_URL);
};

export const reqRoleList = (data: IPage) => {
  return request.post<any, IRoleListResponseData>(API.ALLROLE_URL, data);
};

export const reqDeleteRole = (data: any) => {
  return request.post<any, IDeleteResponseData>(API.DELETEROLE_URL, data);
};

export const reqAddOrUpdateRole = (data: IRole) => {
  return request.post<any, ISave>(API.SAVEROLE_URL, data);
};

export const reqFindRoleMenus = (roleId: number) => {
  return request.get<any, any>(API.ROLEMENUS_URL + "?roleId=" + roleId);
};

export const reqSaveRoleMenus = (data: number) => {
  return request.post<any, any>(API.SAVEROLEMENUS_URL, data);
};
